package com.watson.onebox.sc.springcloud;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.watson.onebox.aspect.TestMethod;
import com.watson.onebox.bean.Dessert;
import com.watson.onebox.bean.IceCream;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class CustomZuulFilter extends ZuulFilter {

    @Resource
    IceCream dessert;

    @Resource
    IceCream iceCream;

    @Resource(name = "iceCream")
    IceCream dessert1;

    @Resource(type = IceCream.class)
    IceCream dessert2;

    @Resource
    TestMethod testMethod;

    @Resource
    TestMethod testMethod1;


    int a = 0;
//    @Resource(type = IceCream2.class)
    Dessert dessert3;
    @Scheduled(fixedDelay = 1000)
    public void test() {
        dessert.setType(a++);
      log.info("{}, {}, {}, {}", dessert.getType(), iceCream.getType(), dessert1.getType(), dessert2.getType());
      log.info("{}, {}", testMethod.getType(), testMethod1);
    }


    @Override
    public Object run() {
        RequestContext ctx = RequestContext.getCurrentContext();
        ctx.addZuulRequestHeader("Test", "TestSample");
        return null;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public String filterType() {
        return null;
    }

    @Override
    public int filterOrder() {
        return 0;
    }
    // ...
}